﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;

namespace Licenta1.Shapes
{
    class Bitsmap:Shape
    {

        System.Drawing.Point p;
        RayTracer.PixelRenderer rnd;
        int w, h;
        

        public Bitsmap(Context con, Bitmap b, System.Drawing.Point p)
            : base(con)
        {
            this.p = p;
        }

        public Bitsmap(Context con, RayTracer.PixelRenderer Pr, int start1, int start2,int end1, int end2)
            : base(con)
        {
            w = end1;
            h = end2;
            rnd = Pr;
            this.p = new System.Drawing.Point(start1, start2);

//            Thread trd = new Thread(new ThreadStart(UpdateBitmap));
//            trd.Start();
            UpdateBitmap(start1, start2);

        }

        
        private void UpdateBitmap(int start, int end)
        {
            for (int i = start; i < w; i++)
            {
                lock (context.mp.myBitmap)
                {
                    for (int j = end; j < h; j++)
                    {
                        //Console.WriteLine("Pixel (" + i + ", " + j + ") = " + rnd(i, j));
                        context.mp.myBitmap.SetPixel(i, j, rnd(i, j));
                    }
                }
            }
        }

        public override void Draw()
        {
            context.mp.objectsList.Add(this);
        }

        public override string Display()
        {
            return base.Display();
        }

        public System.Drawing.Point POS
        {
            get { return p; }
        }
    }
}
